package org.opens.guava.utilites.eventBus.monitor;

import com.google.common.eventbus.EventBus;
import org.junit.Test;

import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class MonitorClient {

    @Test
    public void test1() throws Exception {
        EventBus eventBus = new EventBus();
        TargetMonitor monitor = new DirectoryTargetMonitor(eventBus, "E:\\monitor-test");
        FileChangeListener listener = new FileChangeListener(eventBus);
        //由于执行monitor.startMonitor();会进入阻塞, 所以无法在当前线程中停止这个监视器了, 就需要创建一个异步线程池去停止.
        Executors.newSingleThreadScheduledExecutor().schedule(() -> {
            try {
                monitor.stopMonitor();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, 30, TimeUnit.SECONDS);
        monitor.startMonitor();
    }
}
